/***********************************************************************
 * Module:  NeuralNetworkNode.java
 * Author:  Mladen
 * Purpose: Defines the Class NeuralNetworkNode
 ***********************************************************************/

package raf.neural;

import java.util.Random;
import java.util.*;

import raf.functions.ActivationFunction;

public class NeuralNetworkNode extends raf.core.AbstractNode {

	public ActivationFunction activationFunction;

	private Double[] weights;

	public NeuralNetworkNode(int _inputsCount) {
		weights = new Double[_inputsCount];
	}

	public void calculateOutput(Double[] _input) {
		inputs = _input;
		output = 0.0;
		for (int i = 0; i < weights.length; i++)
			output += weights[i] * inputs[i];
		output = activationFunction.calculate(output);
	}

	public void doCorection(Double[] _newWeights) {
		weights = _newWeights;
	}

	public void initialize() {
		Random random = new Random();
		for (int i = 0; i < weights.length; i++)
			weights[i] = random.nextDouble();
	}

	public void calculateError() {

	}
	
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("[w : ");
		for (Double w : weights) {
			buffer.append(w+" ");
		}
		buffer.append("]\n");
		return buffer.toString();
	}
}